<%@ page language="java" contentType="text/html; charset=UTF-8"
  pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>
<%@include file="/common/extjs.jsp"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<html>
<head>
<%@include file="/common/meta.jsp" %>
<title></title>
<link rel="stylesheet" type="text/css" href="${ctx}/styles/style.css">
<link href="${ctx}/pages/longtian/order/css/order.css" rel="stylesheet" type="text/css">
</head>
<body>
<form action="frontIndex.do" id="queryForm" method="post">
<table width="780" border="0" align="center" cellpadding="0" cellspacing="0" >
  <tr>
    <td align="left">
      &nbsp;编号：&nbsp;<s:textfield name="model.sn" cssStyle="width:100px;"></s:textfield>
	  &nbsp;日期：&nbsp;<input type="text" name="createBeginDate" style="width: 90px"
				value='<s:date name="createBeginDate" format="yyyy-MM-dd"/>'
				onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})"
				class="Wdate" />
      &nbsp;至&nbsp;<input type="text" name="createEndDate" style="width: 90px"
				value='<s:date name="createEndDate" format="yyyy-MM-dd"/>'
				onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})"
				class="Wdate" />
	  &nbsp;状态：<s:select list="#request.frontStatusMap" name="model.status" headerKey="" headerValue="请选择"></s:select>
      &nbsp;&nbsp;<img src="${ctx}/images/icons/zoom.gif">查询
    </td>
  </tr>
</table>
</form>	
<table width="780" align="center" style="margin-top: 0px;" border="0">
	<tr style="height: 30px;">	
		<td width="30%" style="border-bottom: 0px;">&nbsp;</td>		
		<td width="30%" style="border-bottom: 0px;" align="center"><font style="font-weight: bold;">订单列表</font></td>
		<td width="30%" style="border-bottom: 0px;" align="right">共有${myOrders.rows}个订单</td>
	</tr>
</table>
<table width="780"  align="center" cellpadding="0" cellspacing="0" style="border: 1px solid #C0C0C0; " >
	<tr  class="title">
		<td align="center">订单号</td>
		<td>图书</td>
		<td>订单总金额</td>
		<td>订单状态</td>
		<td>下单时间</td>
		<td align="center">操作</td>					
	</tr>
	<c:choose>
		<c:when test="${empty myOrders.data}">
			<tr >
				<td colspan="6" style=" margin-top: 30px;border: 0;text-align: center; height: 200px;">
					<font style="font-size: 18px;">目前还没有订单!</font>
				</td>
			</tr>
		</c:when>
		<c:otherwise>
			<c:forEach items="${myOrders.data}" var="itm" varStatus="status" >
				<tr>	
				<td align="center"><a href="${ctx}/front/orderForm/viewOrder.do?model.id=${itm.id}">${itm.sn }</a></td>				
				<td>
				<c:choose>
					<c:when test="${not empty itm.items}">
						<c:forEach items="${itm.items}" var="orderItem">
							<div style="width: 50px;height: 50px;">
								<a target="_blank"   	href="" 	name="productpic" title="">
		    									<img src="${ctx}${orderItem.book.coverPhoto}"  style="width: 50px;height: 50px;" alt="22">
		    					</a>
							</div>
						</c:forEach>
					</c:when>
					<c:otherwise>
						&nbsp;
					</c:otherwise>
				</c:choose>
				
				</td>
				<td><fmt:formatNumber pattern="#,#00.00#">${itm.money }</fmt:formatNumber></td>
				<td>
					<c:choose>
				         <c:when test="${itm.status eq '0'}">
				         	待审核
				         </c:when>
				         <c:when test="${itm.status eq '1'}">
				         	取消[系统]
				         </c:when>
				         <c:when test="${itm.status eq '2'}">
				         	确认[未付款]
				         </c:when>
				         <c:when test="${itm.status eq '3'}">
				         	已付款
				         </c:when>
				         <c:when test="${itm.status eq '4'}">
				         	已发货
				         </c:when>
				         <c:when test="${itm.status eq '5'}">
				         	完成
				         </c:when>
				         <c:when test="${itm.status eq '6'}">
				         	取消[用户]
				         </c:when>
				         <c:when test="${itm.status eq '7'}">
				         	系统删除
				         </c:when>
       				</c:choose>
				</td>
				<td>
					<fmt:formatDate pattern="yyyy-MM-dd HH:mm:ss" value="${itm.createDate}"></fmt:formatDate>
				</td>
				
				<td align="center"><a href="${ctx}/front/orderForm/viewOrder.do?model.id=${itm.id}">查看</a> | 
					<c:choose>
						<c:when test="${itm.status eq '0' or itm.status eq '2'}">
							<a href="#" onclick="cancelOrder(${itm.id})">取消</a>
						</c:when>
						<c:otherwise>
							<font color="#999999">取消</font>
						</c:otherwise>
					</c:choose>
					
				</td>
			</tr>
			</c:forEach>
		</c:otherwise>
	</c:choose>						
</table>
	<c:if test="${not empty myOrders.data}">		
			<table border="0" align="center" width="780">
			<tr>
				<td width="30%">&nbsp;</td>
				<td align="center" width="20%">
					<a href="${ctx}/cart/viewCart.do">查看购物车<img src="${ctx }/images/longtian/cart.gif"></img></a>
				</td>
				<td align="right">
					<c:choose>
						<c:when test="${myOrders.pageNo > 1}">
							<a name="pg_pre" class="pagebtn" href="#"><span onclick="goPage(1)">首页</span></a>
							<a name="pg_pre" class="pagebtn" href="#"><span onclick="goPage(${myOrders.pageNo - 1})">上一页</span></a>
						</c:when>								
						<c:otherwise>
							<span>首页</span>
							<span">上一页</span>
						</c:otherwise>
					</c:choose>				
					<c:choose>
						<c:when test="${myOrders.pageNo < myOrders.pages}">
							<a name="pg_next" class="pagebtn" href="#" onclick="goPage(${myOrders.pageNo + 1})"><span>下一页</span></a>
							<a name="pg_pre" class="pagebtn" href="#"><span onclick="goPage(${myOrders.pages})">尾页</span></a>
						</c:when>	
						<c:otherwise>
							<span>下一页</span>	
							<span>尾页</span>
						</c:otherwise>
					</c:choose>					
					<span>每页${myOrders.pageSize }条,共${myOrders.pages }页 到第</span>
					<input type="text" id="pageNoInput" style="width: 30px;" value="${myOrders.pageNo}" 
						onkeyup="this.value=this.value.replace(/[^\d]/g,'') " 
						onblur="this.value=this.value.replace(/[^\d]/g,'');checkBlack(this) " id="page">
					<span>页</span>
					<a href="javascript:goPage('')">确定</a>
				</td>	
				<td width="6%">&nbsp;
				</td>			
			</tr>
		</table>			
		<form id="queryFrm" action="${ctx}/front/orderForm/frontIndex.do" method="get" >
			<input id="pageNo" type="hidden" name="pageNo"></input>
		</form>   
           </c:if>

	
	<%-- table class="moneyTable" align="center">
		<tr>
			<td align="right">
				<p class="price">图书金额总计：<span class="moneyRenMinBi">￥<fmt:formatNumber pattern="#,#00.00#">${myTotal}</fmt:formatNumber></span></p>
			</td>
		</tr>
		<tr>
			<td align="right">
			 <c:if test="${model.status eq '0'}">
       			<input type="button" onclick="cancelOrder()" value="取消定单">
       		</c:if> 	
			</td>
		</tr>		
	</table>
	--%>
<script type="text/javascript">
function query(){
	document.getElementById("queryForm").submit();
}
function goPage(arg){
	if(arg != ''){
		document.getElementById('pageNo').value = arg;
	}else{
		document.getElementById('pageNo').value = document.getElementById("pageNoInput").value;
	}
	var frm = document.getElementById("queryFrm");
	
	frm.submit();
}
function checkBlack(arg){
	if(arg.value == ""){
		arg.value = 0;
	}
}
function cancelOrder(orderId){	
	if(confirm('您确定取消订单?')){
		var pageNo = document.getElementById('pageNo').value;
		location.href = '${ctx}/front/orderForm/cancelOrder.do?model.id='+orderId+'&arg=frontIndex&currentPageNo='+pageNo;
	}
}
</script>
</body>
</html>